package com.wy2cloud.user.controller;

import java.util.Random;

import javax.ws.rs.QueryParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.wy2cloud.core.data.PageResult;
import com.wy2cloud.core.date.DateTime;
import com.wy2cloud.core.tools.StringTools;
import com.wy2cloud.core.tools.UUIDTools;
import com.wy2cloud.mybatis.PageTools;
import com.wy2cloud.user.entity.SysUser;
import com.wy2cloud.user.service.SysUserService;



@RestController
public class HomeController {
	private static final Logger logger=LoggerFactory.getLogger(HomeController.class);
	@Autowired
	private SysUserService sysUserService;
	
	@RequestMapping("/")
	public PageResult<SysUser> index() {
		
//		sysUserService.i
		
		SysUser user=new SysUser();
		user.setId(UUIDTools.createUUId());
		Random rnd=new Random();
		
		user.setAccount("user"+String.valueOf(rnd.nextInt(1000)));
		user.setCreateTime(DateTime.Now().getDate());
		user.setSex("男");
		user.setStatus(1);
		
		sysUserService.insert(user);
		
		Page<SysUser> page= sysUserService.selectAll();
		
		logger.debug("count:"+String.valueOf(page.getTotal()));
		logger.debug("getPageSize:"+String.valueOf(page.getPageSize()));
		logger.debug("getPageNum:"+String.valueOf(page.getPageNum()));
		
		return PageTools.toPageResult(page);
	}
	
	@RequestMapping("/getUserByAccount")
	public SysUser getUserByAccount(@RequestParam(value="account") String account) {
		if(StringTools.isEmpty(account)) return null;
		return sysUserService.getUserByAccount(account);
	}
}
